package com.danceforyou.common.service.impl;

import com.danceforyou.common.dao.OperationDAO;
import com.danceforyou.common.model.OperationDO;
import com.danceforyou.common.service.OperationService;
import com.danceforyou.common.util.StringUtil;
import com.danceforyou.common.vo.OperationVO;
import com.danceforyou.user.model.UserDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
* 类名称：OperationServiceImpl
* 创建人：danceforyou
* 创建时间：2021年01月13日
* 版本号：1.0v
*/
@Service("operationService")
public class OperationServiceImpl extends BaseServiceImpl<Long, OperationDO, OperationVO, OperationDAO> implements OperationService {
    @Autowired
    private OperationDAO operationDAO;

    @Override
    public OperationDAO getDao() {
        return operationDAO;
    }

    @Override
    public boolean saveOperation(String tableName, Long tableId, String[] operStr, UserDO operUser, String operInfo) {
        OperationDO operation = new OperationDO();
        operation.setTableName(tableName);
        operation.setTableId(tableId);
        operation.setOperCode(operStr[0]);
        operation.setOperName(operStr[1]);
        operation.setOperDate(new Date());
        operation.setOperUserId(operUser.getId());
        operation.setOperUserName(operUser.getName());
        operation.setOperInfo(StringUtil.isBlank(operInfo) ? null : operInfo);
        int i = operationDAO.insert(operation);
        return i == 1;
    }

    @Override
    public List<OperationDO> getOperationRecord(String tableName, Long tableId) {
        return operationDAO.getOperationRecord(tableName, tableId);
    }
}
